import { App } from '@vue/runtime-dom'

export const install = function (app: App) {
  const HTML = document.documentElement

  const CV = Object.freeze({
    set (key: string, value: string | null, scope = HTML) { scope.style.setProperty(`--${key}`, value) },
    get (key: any, scope = HTML) { return scope.style.getPropertyValue(`--${key}`) },
    del (key: any, scope = HTML) { return scope.style.removeProperty(`--${key}`) },
    setAll (values: { [x: string]: string | null }, scope = HTML) { for (const key in values) { CV.set(key, values[key], scope) } }
  })

  app.provide('CV', CV)
}
